package com.lc.cms.contoller;

import com.lc.cms.dto.PermissionPagingParameterDto;
import com.lc.cms.model.PermissionModel;
import com.lc.cms.service.IPermissionService;
import com.lc.cms.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("permission")
@Log4j2
public class PermissionController {

    private final IPermissionService permissionService;

    @Autowired
    public PermissionController(IPermissionService permissionService) {
        this.permissionService = permissionService;
    }

    @RequestMapping("create")
    public ResponseResult create(PermissionModel permission) {
        Long start = new Date().getTime();
        ResponseResult responseResult = permissionService.create(permission);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult update(PermissionModel permission) {
        Long start = new Date().getTime();
        ResponseResult responseResult = permissionService.update(permission);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("delete")
    public ResponseResult delete(int id) {
        Long start = new Date().getTime();
        ResponseResult responseResult = permissionService.delete(id);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("getListPagingByCondition")
    public ResponseResult getListPagingByCondition(PermissionPagingParameterDto permission) {
        Long start = new Date().getTime();
        ResponseResult responseResult = permissionService.getListPagingByCondition(permission);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
